package com.fairytask.engine.components.radioButton
{
	import com.fairytask.engine.components.BaseComponent;
	
	import flash.display.Sprite;
	/**
	 *	RadioGroup Component  
	 * @author nanz
	 * 
	 */	
	public class RadioButtonGroup extends BaseComponent
	{
		
		public var selectItem	:RadioButton;  //选中的单选按钮
		public var numRadioButton:Array=[];   //radioButton的个数
		private var _curIndex:int	=	-1;
		private var _curName	:String	=	"";

		public function RadioButtonGroup()
		{
			super();
			addEventListener(RadioButtonEvent.RADIO_CLICK, onItemClick);
		}
		
		public function intSelected(index:int):void
		{
			if((index>=numRadioButton.length)||(index<0))
			{
				return;
			}
			for(var i:int	=	0;i<numRadioButton.length;i++)
			{
				(numRadioButton[i] as RadioButton).select	=	false;
			}
			
			(numRadioButton[index] as RadioButton).select=true;
			_curIndex	=	index;
			_curName=numRadioButton[index].name;
		}
		
		public function addRadioButton(radio:RadioButton):void
		{
			if(numRadioButton.indexOf(radio)==-1)
			{
				numRadioButton.push(radio);
			}
		}

		public function get curIndex():int
		{
			return _curIndex;
		}
		
		public function get curName():String
		{
			return _curName;
		}
		
		public function onItemClick(evt:RadioButtonEvent):void
		{			
			var tmpItem:RadioButton	=	evt.radio;
			for each(var item:RadioButton in numRadioButton)
			{		
				if(tmpItem ==  item)
				{
					item.select	=	true;
					_curIndex=numRadioButton.indexOf(tmpItem);
					_curName	=	tmpItem.name;
//					trace("所选中的索引是："+_curIndex);
				}
				else
				{
					item.select	=	false;
				}
			}
		}
	}
}